/* 用深度优先搜索，实现全排列 */

#include<iostream>
#include<algorithm>
using namespace std;

constexpr int N = 6;
int a[N];
int books[N];

void dfs(int step)
{
    if (step == N)
    {
        for_each(begin(a), end(a), [](int e) -> void {cout<< e << " ";});
        cout<< "\n";
        return;
    }

    for (int i = 0; i < N; i++)
    {
        if (books[i] == 0)
        {
            a[step] = i;
            books[i] = 1;

            dfs(step + 1);

            books[i]= 0;
        }
    }
}

int main(void)
{
    dfs(0);
}
